package com.aoxin.service.impl.activity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.activity.SlfSigninConfigMapper;
import com.aoxin.model.activity.SlfSigninConfig;
import com.aoxin.service.inter.activity.SigninConfigService;
import com.aoxin.util.ErrorUtil;

@Service("signinConfigService")
public class SigninConfigServiceImpl implements SigninConfigService{
	
	@Autowired
	private SlfSigninConfigMapper slfSigninConfigMapper;

	@Override
	public SlfSigninConfig getSigninConfig(Integer signinConfigId) {
		Assert.notNull(signinConfigId, String.format(ErrorUtil.PARAMETER_NULL, "signinConfigId"));
		return this.slfSigninConfigMapper.selectByPrimaryKey(signinConfigId);
	}

	@Override
	@Transactional
	public void deleteSigninConfigs(List<Integer> signinConfigIds) {
		Assert.notEmpty(signinConfigIds, String.format(ErrorUtil.PARAMETER_NULL, "signinConfigIds"));
		this.slfSigninConfigMapper.deleteByPrimaryKeys(signinConfigIds);
	}

	@Override
	@Transactional
	public void insertSigninConfig(SlfSigninConfig slfSigninConfig) {
		Assert.notNull(slfSigninConfig, String.format(ErrorUtil.PARAMETER_NULL, "slfSigninConfig"));
		this.slfSigninConfigMapper.insertSelective(slfSigninConfig);
	}

	@Override
	@Transactional
	public void updateSigninConfig(SlfSigninConfig slfSigninConfig) {
		Assert.notNull(slfSigninConfig, String.format(ErrorUtil.PARAMETER_NULL, "slfSigninConfig"));
		this.slfSigninConfigMapper.updateByPrimaryKeySelective(slfSigninConfig);
	}

	@Override
	@Transactional
	public void updateSigninConfigStates(Integer state, List<Integer> signinConfigId) {
		Assert.notNull(state, String.format(ErrorUtil.PARAMETER_NULL, "state"));
		Assert.notEmpty(signinConfigId, String.format(ErrorUtil.PARAMETER_NULL, "signinConfigId"));
		this.slfSigninConfigMapper.updateStates(state, signinConfigId);
	}

	@Override
	public List<SlfSigninConfig> getSigninConfigList() {
		return this.slfSigninConfigMapper.getList();
	}

	@Override
	public List<SlfSigninConfig> getListByUser() {
		
		//计算当前签到组号 TODO
		Integer group = 0;
		
		return this.slfSigninConfigMapper.getListByUser(group);
	}
}
